/**
 * 
 */
package edu.rice.myxo.olexii;

import java.util.ArrayList;

/**
 * @author frogy
 * 
 */
public class Statistics {
	public static double maxV;

	public static double minV;

	public static double[] vArray;

	public static double maxRP;

	public static double minRP;

	public static double[] rpArray;

	int numCellLabeled;

	public void computeMSD(ArrayList<MyxoAgent> list) {

		numCellLabeled = 500;
		int labelnum;
		if (Global.currTime == Global.dT) {
			labelnum = generalLabelCells(list, numCellLabeled);
		} else if ((int) Global.currTime < (int) (Global.simTime * 0.33)) {

		}
	}

	public int generalLabelCells(ArrayList<MyxoAgent> agentList,
			int labeledCellNum) {
		int cellsLabeled = 0;
		for (int i = 0; i < agentList.size(); i++) {
			if (agentList.get(i).getX() > 0.35 * Global.worldX
					&& agentList.get(i).getX() < 0.65 * Global.worldX) {
				if (agentList.get(i).getY() > 0.35 * Global.worldY
						&& agentList.get(i).getY() < 0.65 * Global.worldY) {
					agentList.get(i).setGeneralTrack(true);
					agentList.get(i).generalStatInit();
					cellsLabeled += 1;
				}
			}
			if (cellsLabeled >= labeledCellNum) {
				break;
			}
		}
		labeledCellNum = cellsLabeled < labeledCellNum ? cellsLabeled
				: labeledCellNum;
		return labeledCellNum;
	}

	public double[] findNeighbor(MyxoAgent m) {
		double[] neighborIndex = new double[2];
		double[] neighborZeros = new double[2];
		neighborIndex[0] = -Math.cos(m.getDir()) / Math.abs(Math.cos(m.getDir()));
		neighborIndex[1] = -Math.sin(m.getDir()) / Math.abs(Math.sin(m.getDir()));
		if (Math.abs(Math.sin(m.getDir())) < Math.sqrt(2) / 2) {
			neighborZeros[0] = 1;
			neighborZeros[1] = 0;
		} else {
			neighborZeros[0] = 0;
			neighborZeros[1] = 1;
		}
		double[] neighbor = new double[4];
		neighbor[0] = neighborIndex[0] * neighborZeros[0];
		neighbor[1] = neighborIndex[1] * neighborZeros[1];
		neighbor[2] = -neighborIndex[0] * neighborZeros[0];
		neighbor[3] = -neighborIndex[1] * neighborZeros[1];
		return neighbor;
	}

}
